home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / software-center / softwarecenter / SimpleGtkbuilderApp.py < prev    next >
Text File  |  2009-10-23  |  2KB  |  64 lines

  1. """
  2.  SimpleGladeApp.py
  3.  Module that provides an object oriented abstraction to pygtk and gtkbuilder
  4.  Copyright (C) 2009 Michael Vogt
  5.  based on ideas from SimpleGladeBuilder by Sandino Flores Moreno
  6. """
  7.  
  8. # This library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Lesser General Public
  10. # License as published by the Free Software Foundation; version 3.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this library; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  20. # USA
  21.  
  22. import os
  23. import sys
  24. import re
  25.  
  26. import gtk
  27.  
  28. # based on SimpleGladeApp
  29. class SimpleGtkbuilderApp:
  30.  
  31.     def __init__(self, path, domain):
  32.         self.builder = gtk.Builder()
  33.         self.builder.set_translation_domain(domain)
  34.         self.builder.add_from_file(path)
  35.         self.builder.connect_signals(self)
  36.         for o in self.builder.get_objects():
  37.             if issubclass(type(o), gtk.Buildable):
  38.                 name = gtk.Buildable.get_name(o)
  39.                 setattr(self, name, o)
  40.             else:
  41.                 print >>sys.stderr, "WARNING: can not get name for '%s'" % o
  42.  
  43.     def run(self):
  44.         """
  45.         Starts the main loop of processing events checking for Control-C.
  46.  
  47.         The default implementation checks wheter a Control-C is pressed,
  48.         then calls on_keyboard_interrupt().
  49.  
  50.         Use this method for starting programs.
  51.         """
  52.         try:
  53.             gtk.main()
  54.         except KeyboardInterrupt:
  55.             self.on_keyboard_interrupt()
  56.  
  57.     def on_keyboard_interrupt(self):
  58.         """
  59.         This method is called by the default implementation of run()
  60.         after a program is finished by pressing Control-C.
  61.         """
  62.         pass
  63.  
  64.